# coding=utf-8
# coding:utf-8
import csv
import re
import pandas as pd


# 返回所有的 wifitag
def getwifitag():
	data = pd.read_csv(r'data\result.csv')
	wifitaglist = list(set(data.WIFIAPTag))
	return wifitaglist


def selectthreeday(data):
	resultlist = list()
	for line in data:
		stime = line[2]
		if re.match("2016-09-1[0,1,2,3]-1[5,6,7]-*", stime):
			resultlist.append(line)
			# print line
	print len(resultlist)
	return resultlist


def selectthreeday(data=None):
	datalist = list()
	for line in data:
		stime = line[2]
		if re.match("2016-09-1[3]-1[5,6,7]-*", stime):
			line[2] = stime[0:9] + '4' + stime[10:15]
			datalist.append(line)
			# print line
	print len(datalist)
	return datalist


def writetocvs(filename, datalist):
	csvfile = file('data\\' + filename, 'wb')
	writer = csv.writer(csvfile)
	writer.writerow(['passengerCount', 'WIFIAPTag', 'slice10min'])
	writer.writerows(datalist)


datas = csv.reader(file(r'data\result.csv', 'rb'))
# wifitaglist = getwifitag()
datalists = selectthreeday(datas)
writetocvs("13.csv", datalists)






